﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VirtualDisk
{
    class SimpleCommandFactory
    {
        //通过传入的str生成相应的Command,为了接口一致采用NUllObject模式
        //当用户什么都没输入直接按回车，生成EmptyCommand，执行时什么都不做
        //用户输入不存在的命令，生成NoExistCommand,执行时只打印一行错误信息
        public Command createCommand(MyString str)
        {
            MyString type = Parser.parseCommandName(str);
            MyString[] argu = null;
            if (MyString.IsNullOrEmpty(type))
            {
                return new EmptyCommand();
            }
            MyString typeTemp = type.ToLower();
            switch(typeTemp.ToString())
            {
                case "exit":
                    return new ExitCommand();
                case "mkdir":
                     argu = Parser.parseArgu(str,Parser.NOLIMIT);
                     return new MkdirCommand(argu);
                case "rmdir":
                     argu = Parser.parseArgu(str, 2);
                     return new RmdirCommand(argu);
                case "cd":
                     argu = Parser.parseArgu(str, 1);
                     return new CdCommand(argu);
                case "dir":
                    argu = Parser.parseArgu(str, 2);
                    return new DirCommand(argu);
                case "del":
                    argu = Parser.parseArgu(str, 1);
                    return new DelCommand(argu);
                case "copy":
                    argu = Parser.parseArgu(str, 2);
                    return new CopyCommand(argu);
                case "compare":
                    argu = Parser.parseArgu(str, 2);
                    return new CompareCommand(argu);
                default:
                    return new NoExistCommand();

            }
            
           
        }
    }
}
